
const connection = require('../app/database')

class UserService {
    async create(user) {
        console.log(user);
        const { name, password } = user;
        const statement = `INSERT INTO user (name,password) VALUES (?,?);`;

        const result = await connection.execute(statement, [name, password])

        // 将user存储到数据库中
        return result[0];
    }

    // 查询数据库中有没有这个用户

    async getUserByName(name) {
        const statement = `SELECT * FROM user WHERE name = ?;`;
        const result = await connection.execute(statement, [name]);

        return result[0];
    }
}

module.exports = new UserService();